package org.smartopen.unionpay.openapi.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.smartframework.core.api.Resp;
import org.smartframework.system.log.annotation.SysLog;
import org.smartframework.unionpay.domain.request.SmartProfitSharingFinishRequest;
import org.smartframework.unionpay.domain.request.SmartProfitSharingReceiverRequest;
import org.smartframework.unionpay.domain.request.SmartProfitSharingRequest;
import org.smartframework.unionpay.domain.result.SmartProfitSharingAddReceiverResult;
import org.smartframework.unionpay.domain.result.SmartProfitSharingFinishResult;
import org.smartframework.unionpay.domain.result.SmartProfitSharingRemoveReceiverResult;
import org.smartframework.unionpay.domain.result.SmartProfitSharingResult;
import org.smartframework.unionpay.service.SmartUnionPayService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = {"支付接口"})
@RestController
@RequiredArgsConstructor
public class UnionPayOpenApiProfitSharingController {

    private final SmartUnionPayService unionPayService;

    /**
     * 分账接口
     * @param request
     * @return
     */
    @PostMapping("/profitsharing")
    @ApiOperation("分账接口")
    @SysLog("分账接口")
    public Resp<SmartProfitSharingResult> profitSharing(@RequestBody SmartProfitSharingRequest request) {
        return Resp.ok(unionPayService.profitSharing(request));
    }
    /**
     * 分账接口
     * @param request
     * @return
     */
    @PostMapping("/profitsharing/finish")
    @ApiOperation("分账完结")
    @SysLog("分账完结")
    public Resp<SmartProfitSharingFinishResult> profitSharingFinish(@RequestBody SmartProfitSharingFinishRequest request) {
        return Resp.ok(unionPayService.profitSharingFinish(request));
    }


    /**
     * 商户发起添加分账接收方请求，后续可通过发起分账请求将结算后的钱分到该分账接收方。
     * @param request
     * @return
     */
    @SysLog("添加分账接收方")
    @ApiOperation("添加分账接收方")
    @PostMapping("/profitsharing/receivers/add")
    public Resp<SmartProfitSharingAddReceiverResult> profitSharingAddReceiver(@RequestBody SmartProfitSharingReceiverRequest request) {
        return Resp.ok(unionPayService.profitSharingAddReceiver(request));
    }

    /**
     * 商户发起删除分账接收方请求，删除后不支持将结算后的钱分到该分账接收方。
     *
     * @param request
     * @return
     */
    @ApiOperation("删除分账接收方")
    @SysLog("删除分账接收方")
    @PostMapping("/profitsharing/receivers/remove")
    public Resp<SmartProfitSharingRemoveReceiverResult> profitSharingRemoveReceiver(@RequestBody SmartProfitSharingReceiverRequest request) {
        return Resp.ok(unionPayService.profitSharingRemoveReceiver(request));
    }
}
